package com.css.bjdt_report.report.service;

import java.util.List;

import org.nutz.dao.Dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.css.bjdt_report.cell.entity.Cell;
import com.css.bjdt_report.cell.service.CellService;
import com.css.bjdt_report.report.entity.RptAreaTemporary;

@Service
public class ReportDesignService {
	@Autowired
	private Dao dao;

	@Autowired
	private CellService cellService;

	@Autowired
	private RptAreaTemporaryService rptAreaTemporaryService;

	@Autowired
	private RptAreaCategoryRService rptAreaCategoryRService;

	@Transactional(readOnly = false)
	public void saveRptAreaCategoryCell(List<Cell> cellList, List<RptAreaTemporary> rptAreaTemporaryList,
			String templateId) {
		//先删除报表区域和统计信息集之间的关系
		List<RptAreaTemporary> areaTemporaryList = rptAreaTemporaryService.queryRptAreaTemporaryList(templateId);
		for (RptAreaTemporary rptAreaTemporary : areaTemporaryList) {
			rptAreaCategoryRService.deleteRptAreaCategoryR(rptAreaTemporary.getId());
		}
		//再删除该报表下的所有数据区域
		rptAreaTemporaryService.clearAreaTemporaryByTemplate(templateId);
		//再删除该报表下的所有单元格
		cellService.clear(templateId);
		//保存该张报表报表的所有数据区域
		for (RptAreaTemporary rptAreaTemporary : rptAreaTemporaryList) {
			rptAreaTemporaryService.saveRptAreaTemporary(rptAreaTemporary);
			rptAreaCategoryRService.saveRptAreaCategoryR(rptAreaTemporary.getId(), rptAreaTemporary.getCategoryId());
		}
		//保存所有单元格
		cellService.batchInsert(cellList);
	}

}
